<?php
//require('Header_iframe.php');
include('../db_connect.php');

$view_roster=true;

if($_POST["viewRosterDept"] == ""){
	$add_course=false;
    echo "Sorry, could not validate course department.";
    return;
}
$str_length=strlen($_POST['viewRosterDept']);
if($str_length<2 || $str_length >6){
    echo "Sorry, could not validate course department.";
    return;
}

if($_POST["viewRosterNum"] == "" || !is_numeric($_POST['viewRosterNum'])){
	$add_course=false;
    echo "Sorry, could not validate course number.";
    return;
}
$str_length=strlen($_POST['viewRosterNum']);
if($str_length<2 || $str_length >4){
    echo "Sorry, could not validate course number.";
    return;
}
$courseDept= $_POST['viewRosterDept'];
$courseNum= $_POST['viewRosterNum'];
$i_courseNumber = (int) $courseNum;


//make sure this course does exist
$sql="select id from fb_courses where course_dept='$courseDept' and course_num=$i_courseNumber";
$result = $db->Execute($sql);
$course_id = $result->fields['id'];
if(!$course_id)
{
    $view_roster=false;
    echo "Sorry, we can't find this course.";
    return;
}

//we are validated, search for users in course
if($view_roster){ 
	$sql="select student_ulink from fb_reach_student_courses where course_id=$course_id";
	$result=$db->Execute($sql);
    $num_rec= $result->RecordCount();
    if($num_rec == 0){
        echo "No students are currently added to this course.";
        return;
    }
    //we have some record(s)...display in a table
    echo "<table class=\"small\" cellspacing=\"5\">";
    echo "<tr><td><b>ULink ID</b></td><td><b>First Name</b></td><td><b>Last Name</b></td><td><b>Verified?</b></td></tr>";
    while(!$result->EOF){
            $curr_id=$result->fields['student_ulink'];
            $sql2="select fb_first_name, fb_last_name,reach_verified from fb_users where ulink_id='$curr_id'";
            $result2=$db->Execute($sql2);
            echo "<tr><td>".$curr_id."</td><td>".$result2->fields['fb_first_name']. "</td><td>".$result2->fields['fb_last_name'];
            if( $result2->fields['reach_verified']==1)
                echo "</td><td>"."Yes"."</td></tr>";
            else
                echo "</td><td>"."No"."</td></tr>";
                
        $result->MoveNext();
    }
    echo "</table>";
}
?>
